Micron Document
Livres et Wikis | Archives | Info


JavaScript syntax
part 5/43 Β· 161.3 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
continues until the end of the line. They are only valid at the start of
files and are intended for use in CLI environments.cite-ref-4[4]

#! Hashbang comment
// One-line comment
/* Multi-line
comment */

Variables

Variables in standard JavaScript have no type attached, so any value
(each value has a type) can be stored in any variable. Starting with
ES6, the 6th version of the language, variables could be declared with
var for function scoped variables, and let or const which are for
block level variables. Before ES6, variables could only be declared with
a var statement. Values assigned to variables declared with const cannot
be changed, but their properties can. var should no longer be used since
let and const are supported by modern browsers.cite-ref-5[5] A variable's
identifier must start with a letter, underscore (_), or dollar sign ($),
while subsequent characters can also be digits (0-9). JavaScript is case
sensitive, so the uppercase characters "A" through "Z" are different
from the lowercase characters "a" through "z".

Starting with JavaScript 1.5, ISO 8859-1 or Unicode letters (or \uXXXX
Unicode escape sequences) can be used in identifiers.cite-ref-6[6] In certain
JavaScript implementations, the at sign (@) can be used in an
identifier, but this is contrary to the specifications and not supported
in newer implementations.

Scoping and hoisting

Variables declared with var are lexically scoped at a function level,
while ones with let or const have a block level scope. Since
declarations are processed before any code is executed, a variable can
be assigned to and used prior to being declared in the code.cite-ref-7[7] This is
referred to as hoisting, and it is equivalent to variables being
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────